package cn.rongdao.jrkabao.ui.main.mainfragment.uicomponent;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.mifengkong.frtools.util.FRImageLoad;
import com.mifengkong.frwidget.banner.customerbanner.BannerAdapter;
import com.mifengkong.frwidget.banner.customerbanner.BannerView;

import java.util.List;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.main.banner.BannerBean;

/**
 * Created by jack on 17/5/20
 */

public class BannerUIComponent extends BannerView {

    public BannerUIComponent(Context context) {
        super(context);
    }

    public BannerUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BannerUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private BannerAdapter adapter;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setIndicatorShowWhenOneCount(false);
        setmIndicaatorNormalDrawable(ContextCompat.getDrawable(getContext(), R.drawable.dot_unselected));   //未选中
        setmIndicaatorFousDrawable(ContextCompat.getDrawable(getContext(), R.drawable.dot_selected));   //已选中
    }

    public void setBannerList(final List<BannerBean> list) {
        setVisibility(View.VISIBLE);
        if (null == adapter) {
            adapter = new BannerAdapter() {
                @Override
                public View getView(int position, View convertView) {
                    ImageView imageView = new ImageView(getContext());
                    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                    FRImageLoad.loadImage(list.get(position).getAd_pic(), imageView);
                    return imageView;
                }

                public int getCount() {
                    return list == null ? 0 : list.size();
                }
            };
            setAdapter(adapter);
        }
    }
}